<?php
class HtmlController extends Controller{
    public function actionIndex(){

    }

    public function actionCreate(){
        $model = new HTMLBlock();

        if(isset($_POST['HTMLBlock'])){
            $model->attributes = $_POST['HTMLBlock'];

            if($model->save()){
                user()->setFlash('success', 'Create block successfully!');

                //update
            }
        }

        $this->render('create', array(
            'model' => $model
        ));
    }

    public function actionUpdate($id){
        $model = HTMLBlock::model()->findByPk($id);

        if(!$model){
            throw new CHttpException(404, 'Page was not exists!');
        }

        if(isset($_POST['HTMLBlock'])){
            $model->attributes = $_POST['HTMLBlock'];

            if($model->save()){
                user()->setFlash('success', 'Update block successfully!');

                //update
                $this->redirect(array('update', 'id' => $model->block_id));
            }
        }

        $this->render('update', array(
            'model' => $model
        ));
    }
}